/**
 * dao接口生成器
 * @author dengzongrong
 * @version 1.1
 * @date 2011-10-09
 */
package com.lemon.ai.socket.packets.spiritgame.model.generator;
import static com.lemon.ai.socket.packets.spiritgame.model.generator.utils.StringUtils.*;
import java.util.List;

import com.lemon.ai.socket.packets.spiritgame.model.db.MetaData;
import com.lemon.ai.socket.packets.spiritgame.model.dto.Table;
import com.lemon.ai.socket.packets.spiritgame.model.generator.utils.DbUtils;

public class DaoIfcGenerator extends AbstractGenerator {

	public DaoIfcGenerator() {
		super("DaoIfcTemp.txt");
	}

	public String generate(Table table) {
		return super.temp.replace("PACKAGE_NAME",super.prop.getProperty("package")).
				replace("CLASS_NAME", generateClassName(table.getName())).
				replace("CLASS_PARAMETER", generateParameterName(table.getName())).
				replace("PK_PARAMETERS", DbUtils.generatePkParameters(table));
	}

	public String generateFileName(Table table) {
		return super.prop.getProperty("dir")
				+ super.prop.getProperty("package").replace(".", "\\")
				+ "\\dao\\" + generateClassName(table.getName())
				+ "DAO.java";
	}

	public static void main(String[] args) {
		MetaData meta = MetaData.getInstance();
		List<Table> tables = meta.getTables();
		DaoIfcGenerator g = new DaoIfcGenerator();
		System.out.println(g.generate(tables.get(0)));
	}

}
